package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShopingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
public class ShoppingCarController {
    @Autowired
    ShopingCartService shopingCartService;

    @PostMapping("/add")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        shopingCartService.add(shoppingCartDTO);
return Result.success();
    }
@GetMapping("/list")
    public Result getShopingCarts(){
      List<ShoppingCart> result = shopingCartService.getShopCarts();
return  Result.success(result);
}
@DeleteMapping("/clean")
    public Result delete(){
        shopingCartService.clean();
        return Result.success();
}
@PostMapping("/sub")
    public Result deleteByid(@RequestBody ShoppingCartDTO shoppingCartDTO){
shopingCartService.cleanBydto(shoppingCartDTO);
return Result.success();
}
}
